package com.wyh.common.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.wyh.common.enums.ResultCodeEnum;

/**
 * <p>
 *
 * </p>
 *
 * @author 骸音
 * @since 2024-5-14
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
    /**
     * 状态码
     */
    private String code;
    /**
     * 返回 mesg
     */
    private String msg;
    /**
     * 返回数据
     */
    private T data;

    /**
     * 总条数
     */
    private Long total;

    public Result(T data) {
        this.data = data;
    }

    public Result() {

    }

    public Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public static <T> Result<T> success(ResultCodeEnum resultCodeEnum) {
        Result<T> tResult = new Result<>();
        tResult.setCode(resultCodeEnum.code);
        tResult.setMsg(resultCodeEnum.msg);
        return tResult;
    }


    public static <T> Result<T> success(ResultCodeEnum resultCodeEnum,T data) {
        Result<T> tResult = new Result<>();
        tResult.setCode(resultCodeEnum.code);
        tResult.setMsg(resultCodeEnum.msg);
        tResult.setData(data);
        return tResult;
    }

    public static <T> Result<T> success() {
        Result<T> tResult = new Result<>();
        tResult.setCode(ResultCodeEnum.SUCCESS.code);
        tResult.setMsg(ResultCodeEnum.SUCCESS.msg);
        return tResult;
    }

    public static <T> Result<T> success(T data) {
        Result<T> tResult = new Result<>(data);
        tResult.setCode(ResultCodeEnum.SUCCESS.code);
        tResult.setMsg(ResultCodeEnum.SUCCESS.msg);
        return tResult;
    }

    public static <T> Result<T> success(T data,Long total) {
        Result<T> tResult = new Result<>(data);
        tResult.setTotal(total);
        tResult.setCode(ResultCodeEnum.SUCCESS.code);
        tResult.setMsg(ResultCodeEnum.SUCCESS.msg);
        return tResult;
    }
    public static <T> Result<T> error() {
        Result<T> tResult = new Result<>();
        tResult.setCode(ResultCodeEnum.SYSTEM_ERROR.code);
        tResult.setMsg(ResultCodeEnum.SYSTEM_ERROR.msg);
        return tResult;
    }

    public static <T> Result<T> error(T data) {
        Result<T> tResult = new Result<>(data);
        tResult.setCode(ResultCodeEnum.PARAM_ERROR.code);
        tResult.setMsg(ResultCodeEnum.PARAM_ERROR.msg);
        return tResult;
    }

    public static <T> Result<T> errorCharging(T data) {
        Result<T> tResult = new Result<>(data);
        tResult.setCode(ResultCodeEnum.SYSTEM_ERROR.code);
        tResult.setMsg(ResultCodeEnum.SYSTEM_ERROR.msg);
        return tResult;
    }

    public static <T> Result<T> error(String code, String msg) {
        Result<T> tResult = new Result<>();
        tResult.setCode(code);
        tResult.setMsg(msg);
        return tResult;
    }

    public static <T> Result<T> error(ResultCodeEnum resultCodeEnum) {
        Result<T> tResult = new Result<>();
        tResult.setCode(resultCodeEnum.code);
        tResult.setMsg(resultCodeEnum.msg);
        return tResult;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setData(T data,Long total) {
        this.data = data;
        this.total=total;
    }
}
